<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="referrer" content="no-referrer-when-downgrade">
    

    <title>深入浅出之自定义渲染Widget | 早起的年轻人</title>
    <meta property="og:title" content="深入浅出之自定义渲染Widget - 早起的年轻人">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2021-09-14T10:10:05&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2021-09-14T10:10:05&#43;08:00'>
        
    <meta name="Keywords" content="Flutter，golang,go语言,go语言笔记,飞雪无情,java,android,博客,项目管理,python,软件架构,公众号,小程序">
    <meta name="description" content="深入浅出之自定义渲染Widget">
        
    <meta name="author" content="luckly">
    <meta property="og:url" content="https://luckly.work/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8B%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B2%E6%9F%93Widget/">
    <link rel="shortcut icon" href='/favicon.ico'  type="image/x-icon">

    <link rel="stylesheet" href='/css/normalize.css'>
    <link rel="stylesheet" href='/css/style.css'>
    <script type="text/javascript" src="//cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    
    
        <link href="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet">
    
    
    
    
        <link rel="stylesheet" href='/css/douban.css'>
    
        <link rel="stylesheet" href='/css/other.css'>
    
</head>

<link rel="stylesheet"
      href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"></script>
<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://luckly.work/">
                        早起的年轻人
                    </a>
                
                <p class="description">专注于Flutter、Android、Java、Go语言(golang)、移动互联网、项目管理、软件架构</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://luckly.work/">首页</a>
                    
                    <a  href="https://luckly.work/categories/" title="分类">分类</a>
                    
                    <a  href="https://luckly.work/tags/" title="标签">标签</a>
                    
                    <a  href="https://luckly.work/archives/" title="归档">归档</a>
                    
                    <a  href="https://luckly.work/about/" title="关于我">关于我</a>
                    
                    <a  href="https://github.com/ITmxs/" title="github">github</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#leafrenderobjectwidget">LeafRenderObjectWidget</a></li>
    <li><a href="#leaf-render-object">Leaf Render Object</a></li>
  </ul>

  <ul>
    <li><a href="#multichildrenderobjectwidget">MultiChildRenderObjectWidget</a></li>
    <li><a href="#richscoreparentdata">RichScoreParentData</a></li>
    <li><a href="#multichild-renderobject">MultiChild RenderObject</a></li>
    <li><a href="#richscoreparentdatascoretextwidth">RichScoreParentData#scoreTextWidth</a></li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">深入浅出之自定义渲染Widget</h1>
        </header>
        <date class="post-meta meta-date">
            2021年9月14日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='/categories/Flutter'>Flutter</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <p>本文是『 深入浅出 Flutter Framework 』系列文章的第八篇，也是收官之作。通过自定义渲染型 Widget，我们一步步地实现了一个评分组件。</p>
<h1 id="overview">Overview</h1>
<hr>
<p>本文作为『 深入浅出 Flutter Framework 』系列文章的收官之作，为了对本系列文章所涉重点内容的回顾和总结，动手实现一个渲染型 Widget (Render-Widget)。
如下图，最终成品是一个评分组件 (源码已上传 Github: <a href="https://github.com/zxfcumtcs/Score">Score</a>)：
<a href="https://zxfcumtcs.github.io/img/Score.gif">
        <a data-fancybox="gallery" href="https://zxfcumtcs.github.io/img/Score.gif">
            <img class="mx-auto" alt="img" src="https://zxfcumtcs.github.io/img/Score.gif" />
        </a>
    </a></p>
<p>通过前面系列文章的介绍，我们知道 Render-Widget 大致有三类：</p>
<ul>
<li>作为『 Widget Tree 』的叶节点，也是最小的 UI 表达单元，一般继承自<code>LeafRenderObjectWidget</code>；</li>
<li>有一个子节点 ( Single Child )，一般继承自<code>SingleChildRenderObjectWidget</code>；</li>
<li>有多个子节点 ( Multi Child )，一般继承自<code>MultiChildRenderObjectWidget</code>。</li>
</ul>
<p>Widget 间的继承关系如下图：
<a href="https://zxfcumtcs.github.io/img/Widget.png">
        <a data-fancybox="gallery" href="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Widget.png">
            <img class="mx-auto" alt="img" src="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Widget.png" />
        </a>
    </a></p>
<p>Widget、Element、RenderObject 间的对应关系如下：
<a href="https://zxfcumtcs.github.io/img/Widget-Element-RenderObject.png">
        <a data-fancybox="gallery" href="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Widget-Element-RenderObject.png">
            <img class="mx-auto" alt="img" src="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Widget-Element-RenderObject.png" />
        </a>
    </a></p>
<blockquote>
<p>其中，Element 与 RenderObject 间用的是虚线，因为它们间的对应关系是基于 RenderBox 系列下的一种建议 (不是强制)。
Sliver 系列就不是基于<code>RenderBox</code>，而是<code>RenderSliver</code>。
通过<code>Render-Widget#createRenderObject</code>方法可以返回任意 RenderObject (如果你愿意)。</p>
</blockquote>
<p>对于<code>RenderBox</code>系列来说，如果要自定义子类，根据自定义子类子节点模型的不同需要有不同的处理：</p>
<ul>
<li>
<p>自定义子类本身是『 Render Tree 』的叶子节点，一般直接继承自<code>RenderBox</code>；</p>
</li>
<li>
<p>有一个子节点 (Single Child)，且子节点属于</p>
<pre><code>RenderBox
</code></pre><p>系列：</p>
<ul>
<li>如果其自身的 size 完全 match 子节点的 size，则可以选择继承自<code>RenderProxyBox</code>(如：<code>RenderOffstage</code>)；</li>
<li>如果其自身的 size 大于子节点的 size，则可以选择继承自<code>RenderShiftedBox</code>(如：<code>RenderPadding</code>)；</li>
</ul>
</li>
<li>
<p>有一个子节点 (Single Child)，但子节点不属于<code>RenderBox</code>系列，自定义子类可以 mixin <code>RenderObjectWithChildMixin</code>，其提供了管理一个子节点的模型；</p>
</li>
<li>
<p>有多个子节点 (Multi Child)，自定义子类可以 mixin <code>ContainerRenderObjectMixin</code>、<code>RenderBoxContainerDefaultsMixin</code>，前者提供了管理多个子节点的模型，后者提供了基于<code>ContainerRenderObjectMixin</code>的一些默认实现。</p>
</li>
</ul>
<p>下面，我们一步步地来实现上面提到的评分组件。</p>
<h1 id="custom-leaf-render-widget">Custom Leaf Render Widget</h1>
<hr>
<p>首先，我们来实现评分组件里的五星部分 (ScoreStar Widget)：
<a href="https://zxfcumtcs.github.io/img/Stars.png">
        <a data-fancybox="gallery" href="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Stars.png">
            <img class="mx-auto" alt="img" src="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Stars.png" />
        </a>
    </a></p>
<h2 id="leafrenderobjectwidget">LeafRenderObjectWidget</h2>
<p><code>ScoreStar</code>作为叶子节点，继承自<code>LeafRenderObjectWidget</code>，并实现了2个重要方法：<code>createRenderObject</code>、<code>updateRenderObject</code>：</p>
<pre><code>class ScoreStar extends LeafRenderObjectWidget {
  final Color backgroundColor;
  final Color foregroundColor;
  final double score;

  ScoreStar(this.backgroundColor, this.foregroundColor, this.score);

  @override
  RenderObject createRenderObject(BuildContext context) {
    return RenderScoreStar(backgroundColor, foregroundColor, score);
  }

  @override
  void updateRenderObject(BuildContext context, covariant RenderScoreStar renderObject) {
    renderObject
      ..backgroundColor = backgroundColor
      ..foregroundColor = foregroundColor
      ..score = score;
  }
}
</code></pre><p>其中，<code>updateRenderObject</code>方法会在 Widget re-build 时调用，用于更新复用的 Render Object 的属性。
在本例中，<code>score</code>会随着用户点击不同的区域而变化，就需要通过<code>updateRenderObject</code>方法来更新<code>RenderScoreStar#score</code>，以便刷新 UI。</p>
<h2 id="leaf-render-object">Leaf Render Object</h2>
<p>从上一小节<code>ScoreStar#createRenderObject</code>可知，<code>ScoreStar</code> 对应的 Render Object 是<code>RenderScoreStar</code>。
<code>RenderScoreStar</code>继承自<code>RenderBox</code>。</p>
<p>如下代码：</p>
<ul>
<li>
<p>在 <code>socre setter</code> 中调用了<code>markNeedsPaint</code>方法，以便在<code>score</code>变化后及时 re-paint (由于 socre 变化不会引起 layout 变化，故此处只需调用<code>markNeedsPaint</code>，若会引起 layout 变化，则需要调用<code>markNeedsLayout</code>)；</p>
</li>
<li>
<p>关于</p>
<pre><code>sizedByParent
</code></pre><p>，在该例子中设为</p>
<pre><code>true
</code></pre><p>or</p>
<pre><code>false
</code></pre><p>都可以，因为</p>
<pre><code>RenderScoreStar#size
</code></pre><p>完全由</p>
<pre><code>constraints
</code></pre><p>决定：</p>
<ul>
<li>从性能角度考虑，<code>sizedByParent</code>应设为<code>true</code>，以便满足<code>RepaintBoundary</code>的条件 (详情请参见[ <a href="https://zxfcumtcs.github.io/2021/03/27/deepinto-flutter-renderobject/">深入浅出 Flutter Framework 之 RenderObject</a> ] )；</li>
<li>若<code>sizedByParent</code>设为<code>true</code>，需要重写<code>performResize</code>方法来计算 size，由于<code>RenderScoreStar</code>没有 layout 操作需要执行，故不需要重写<code>performLayout</code>；</li>
<li>若<code>sizedByParent</code>设为<code>false</code>，则需要重写<code>performLayout</code>，并在该方法中完成 size 的计算；</li>
<li><code>22~30</code>、<code>32~40</code>两个代码片段随便使用哪个都可以。</li>
</ul>
</li>
<li>
<p>关于IntrinsicWidth/Height，若重写了</p>
<pre><code>performLayout
</code></pre><p>方法，则进而需要重写以下四个方法：</p>
<ul>
<li><code>double computeMaxIntrinsicWidth(double height)</code>：用于计算一个最小宽度(没错，是最小宽度)，在最终 size.width 超过该宽度时，也不会减少 size.height (如，对 text 排版，将 text 排成一行需要的最小宽度就是这里的 MaxIntrinsicWidth，因为再增加宽度也不会减少 text 的高度)；</li>
<li><code>double computeMinIntrinsicWidth(double height)</code>：排版需要的最小宽度，若小于这个宽度内容就会被裁剪；</li>
<li><code>computeMinIntrinsicHeight</code>、<code>computeMaxIntrinsicHeight</code>与上面介绍的<code>computeMinIntrinsicWidth</code>、<code>computeMaxIntrinsicWidth</code>类似，不再赘述；</li>
<li>在一些特殊 RenderObject 排版时才会用到这些方法，在此我们根据 constraints 简单计算了一下。</li>
</ul>
</li>
<li>
<p>为了响应点击事件，重写<code>hitTestSelf</code>方法，并返回<code>true</code>，表示该 Render Object 需要响应用户事件；</p>
</li>
<li>
<p>关于</p>
<pre><code>paint
</code></pre><p>方法中五角星 ★★★★★ 的绘制：</p>
<ul>
<li>对于背景 ★★★★★，设置好 path 后，直接通过<code>context.canvas.drawPath</code>绘制即可；</li>
<li>对于前景 ★★★★★，先通过<code>context.pushClipRect</code>对画布进行裁剪 ( rect.width 由 score 决定 )，再行绘制。</li>
</ul>
</li>
</ul>
<pre><code>// 为了缩减篇幅，精简了部分代码
//
class RenderScoreStar extends RenderBox {
  Color _backgroundColor;
  ...

  Color _foregroundColor;
  ...

  double _score;
  double get score =&gt; _score;
  set score(double value) {
    _score = value;
    
    // score 变化时需要re-paint
    //
    markNeedsPaint();
  }

  RenderScoreStar(this._backgroundColor, this._foregroundColor, this._score);

  @override
  bool get sizedByParent =&gt; false;

  @override
  void performLayout() {
    double height = min(constraints.biggest.height, constraints.biggest.width / 5);
    height = max(height, constraints.smallest.height);
    size = Size(constraints.biggest.width, height);
  }

  // @override
  // bool get sizedByParent =&gt; true;
  //
  // @override
  // void performResize() {
  //   double height = min(constraints.biggest.height, constraints.biggest.width / 5);
  //   height = max(height, constraints.smallest.height);
  //   size = Size(constraints.biggest.width, height);
  // }

  @override
  double computeMaxIntrinsicWidth(double height) {
    return constraints.biggest.width;
  }

  @override
  double computeMaxIntrinsicHeight(double width) {
    double height = min(constraints.biggest.height, constraints.biggest.width / 5);
    height = max(height, constraints.smallest.height);

    return height;
  }

  @override
  bool hitTestSelf(Offset position) {
    return true;
  }

  @override
  void paint(PaintingContext context, Offset offset) {
    void _backgroundStarPainter(PaintingContext context, Offset offset) {
      _starPainter(context, offset, backgroundColor);
    }

    void _foregroundStarPainter(PaintingContext context, Offset offset) {
      _starPainter(context, offset, foregroundColor);
    }

    _backgroundStarPainter(context, offset);
    context.pushClipRect(
        needsCompositing,
        offset,
        Rect.fromLTRB(0, 0, size.width * score / 5, size.height),
        _foregroundStarPainter
    );
  }

  void _starPainter(PaintingContext context, Offset offset, Color color) {
    Paint paint = Paint();
    paint.color = color;
    paint.style = PaintingStyle.fill;

    double radius = min(size.height / 2, size.width/ (2 * 5));

    Path path = Path();
    _addStarLine(radius, path);
    for (int i = 0; i &lt; 4; i++) {
      path = path.shift(Offset(radius * 2, 0.0));
      _addStarLine(radius, path);
    }

    path = path.shift(offset);
    path.close();

    context.canvas.drawPath(path, paint);
  }

  void _addStarLine(double radius, Path path) {
    ...
  }
}
</code></pre><p>至此，<code>RenderScoreStar</code>基本完成，完整代码请参见 [ Github：<a href="https://github.com/zxfcumtcs/Score">Score</a> ]</p>
<h1 id="动态评分">动态评分</h1>
<hr>
<p>如下图，我们希望评分组件不仅能展示分数，还能评分：
<a href="https://zxfcumtcs.github.io/img/Score_small.gif">
        <a data-fancybox="gallery" href="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Score_small.gif">
            <img class="mx-auto" alt="img" src="https://luckly007.oss-cn-beijing.aliyuncs.com/image/Score_small.gif" />
        </a>
    </a></p>
<p>在 Flutter UI 中，一个重要的思想就是：『 组合 』。
为了实现上图所示效果，只需组合<code>StatefulWidget</code> +<code>ScoreStar</code>即可：</p>
<pre><code>typedef ScoreCallback = void Function(double score);

class Score extends StatefulWidget {
  final double score;
  final ScoreCallback callback;

  const Score({Key key, this.score = 0, this.callback}) : super(key: key);

  @override
  _ScoreState createState() =&gt; _ScoreState();
}

class _ScoreState extends State&lt;Score&gt; {

  double score;

  @override
  void initState() {
    super.initState();

    score = widget.score ?? 0;
  }

  @override
  void didUpdateWidget(Score oldWidget) {
    super.didUpdateWidget(oldWidget);

    score = widget.score ?? 0;
  }

  @override
  Widget build(BuildContext context) {
    void _changeScore(Offset offset) {
      Size _size = context.size;
      double offsetX = min(offset.dx, _size.width);
      offsetX = max(0, offsetX);

      setState(() {
        score = double.parse(((offsetX / _size.width) * 5).toStringAsFixed(1));
      });

      if (widget.callback != null) {
        widget.callback(score);
      }
    }

    return GestureDetector(
      child: ScoreStar(Colors.grey, Colors.amber, score),
      onTapDown: (TapDownDetails details) {
        _changeScore(details.localPosition);
      },
      onLongPressMoveUpdate:(LongPressMoveUpdateDetails details) {
        _changeScore(details.localPosition);
      },
    );
  }
}
</code></pre><p>代码比较简单，就不赘述了。
其中的关键还是上节介绍的<code>RenderScoreStar#hitTestSelf</code>需要返回<code>true</code>。</p>
<h1 id="custom-multichild-renderobject-widget">Custom MultiChild RenderObject Widget</h1>
<hr>
<p><a href="https://zxfcumtcs.github.io/img/Score.gif">
        <a data-fancybox="gallery" href="https://zxfcumtcs.github.io/img/Score.gif">
            <img class="mx-auto" alt="img" src="https://zxfcumtcs.github.io/img/Score.gif" />
        </a>
    </a>
我们希望通过自定义 MultiChild RenderObject Widget 实现如上图所示的效果。
没错，就是加了一个显示分数的 Text。</p>
<blockquote>
<p>本来，这完全没必要通过自定义 MultiChild RenderObject Widget 来实现，一般的 Widget 组合即可。
我们只是为了实践自定义 MultiChild RenderObject Widget 才这么做的。</p>
</blockquote>
<h2 id="multichildrenderobjectwidget">MultiChildRenderObjectWidget</h2>
<p><code>RichScore</code>继承自<code>MultiChildRenderObjectWidget</code>。
在其初始化方法中，向父类传递了2个 children：<code>Score</code>、<code>Text</code>。
重写了<code>createRenderObject</code>方法，以便返回<code>RenderRichScore</code>实例。
由于<code>RenderRichScore</code>没有属性，故无需重写<code>updateRenderObject</code>方法。</p>
<pre><code>class RichScore extends MultiChildRenderObjectWidget {
  RichScore({
    Key key,
    double score,
    ScoreCallback callback,
  }) : super(
    key: key,
    children: [
      Score(score: score, callback: callback),
      Text('$score分', style: TextStyle(fontSize: 28)),
    ]
  );

  @override
  RenderObject createRenderObject(BuildContext context) {
    return RenderRichScore();
  }
}
</code></pre><h2 id="richscoreparentdata">RichScoreParentData</h2>
<p>还记得 ParentData 吗？</p>
<blockquote>
<p>在<a href="https://zxfcumtcs.github.io/2020/05/01/deepinto-flutter-widget/">『 深入浅出 Flutter Framework 之 Widget 』</a>中有过简单介绍。</p>
</blockquote>
<p>对于含有子节点的 RenderObject，一般都需要自定义自己的 ParentData 子类，用于辅助 layout。</p>
<pre><code>class RichScoreParentData extends ContainerBoxParentData&lt;RenderBox&gt; {
  double scoreTextWidth;
}
</code></pre><p><code>RichScoreParentData</code>继承自<code>ContainerBoxParentData</code>：</p>
<pre><code>/// Abstract ParentData subclass for RenderBox subclasses that want the
/// ContainerRenderObjectMixin.
///
/// This is a convenience class that mixes in the relevant classes with
/// the relevant type arguments.
abstract class ContainerBoxParentData&lt;ChildType extends RenderObject&gt; extends BoxParentData with ContainerParentDataMixin&lt;ChildType&gt; { }
</code></pre><p><code>ContainerBoxParentData</code>是抽象类，但其 mixin<code>ContainerParentDataMixin</code>：</p>
<pre><code>/// Parent data to support a doubly-linked list of children.
mixin ContainerParentDataMixin&lt;ChildType extends RenderObject&gt; on ParentData {
  /// The previous sibling in the parent's child list.
  ChildType previousSibling;
  /// The next sibling in the parent's child list.
  ChildType nextSibling;
}
</code></pre><p><code>ContainerParentDataMixin</code>在子节点间提供了双向链接的支持。</p>
<p>在<code>RichScoreParentData</code>中定义了唯一一个属性：<code>scoreTextWidth</code>，其作用在后面再介绍。</p>
<h2 id="multichild-renderobject">MultiChild RenderObject</h2>
<p><code>RenderRichScore</code>继承自<code>RenderBox</code>并 minix 了<code>ContainerRenderObjectMixin</code>以及<code>RenderBoxContainerDefaultsMixin</code>：</p>
<ul>
<li>由于<code>RenderRichScore#size</code>受子节点的影响，即不完全由 Constraints 决定，故<code>sizedByParent</code>设为<code>false</code>，同时在调用子节点的<code>layout</code>方法时<code>parentUsesSize</code>参数需设为<code>true</code> (下面代码第<code>40</code>、<code>55</code>行)；</li>
<li>由于其子节点 (<code>RenderScoreStar</code>)需要响应用户事件，故重写了<code>hitTestChildren</code>方法；</li>
<li>在<code>performLayout</code>方法中，完成了所有子节点的排版、设置相应的 ParentData 并计算出了 size；</li>
<li>对于有子节点的 RenderObject 需要重写<code>computeDistanceToActualBaseline</code>方法，这里我们用了<code>RenderBoxContainerDefaultsMixin</code>提供的默认实现；</li>
<li><code>paint</code>方法的功能很简单，依次绘制每个子节点(<code>defaultPaint</code>由<code>RenderBoxContainerDefaultsMixin</code>提供)；</li>
<li><code>setupParentData</code>用于给子节点设置<code>parentData</code>。</li>
</ul>
<pre><code>class RenderRichScore extends RenderBox with ContainerRenderObjectMixin&lt;RenderBox, RichScoreParentData&gt;,
    RenderBoxContainerDefaultsMixin&lt;RenderBox, RichScoreParentData&gt;,
    DebugOverflowIndicatorMixin {

  RenderRichScore({
    List&lt;RenderBox&gt; children,
  }) {
    addAll(children);
  }

  @override
  bool get sizedByParent =&gt; false;

  final double horizontalSpace = 10;
  final double scoreTextWidthDifference = 10;

  @override
  bool hitTestChildren(BoxHitTestResult result, { Offset position }) {
    assert(childCount == 2);

    RenderBox scoreChild = firstChild;
    return scoreChild?.hitTest(result, position: position) ?? false;
  }

  @override
  void performLayout() {
    assert(childCount == 2);

    RenderBox scoreStarChild = firstChild;
    RenderBox scoreTextChild = lastChild;

    if (scoreStarChild == null || scoreTextChild == null) {
      size = constraints.smallest;
      return;
    }

    // infinity constraints
    //
    BoxConstraints descConstraints = BoxConstraints();
    scoreTextChild.layout(descConstraints, parentUsesSize: true);

    final RichScoreParentData descChildParentData = scoreTextChild.parentData as RichScoreParentData;
    double descWidth = descChildParentData.scoreTextWidth;
    if (descWidth == null) {
      descWidth = scoreTextChild.size.width + scoreTextWidthDifference;
      descChildParentData.scoreTextWidth = descWidth;
    }

    BoxConstraints scoreConstraints = BoxConstraints(
      minWidth: 0,
      maxWidth: max(constraints.maxWidth - descWidth - horizontalSpace, 0),
      minHeight: 0,
      maxHeight: constraints.maxHeight
    );
    scoreStarChild.layout(scoreConstraints, parentUsesSize: true);

    descChildParentData.offset = Offset(
      scoreStarChild.size.width + horizontalSpace,
      (scoreStarChild.size.height - scoreTextChild.size.height) / 2
    );

    if (constraints.isTight) {
      size = constraints.biggest;
    }
    else {
      double width = min(constraints.biggest.width, scoreStarChild.size.width + descWidth + horizontalSpace);
      width = max(constraints.smallest.width, width);

      double height = max(scoreStarChild.size.height, scoreTextChild.size.height);
      height = min(constraints.biggest.height, height);
      height = max(constraints.smallest.height, height);

      size = Size(width, height);
    }
  }
  
  ...

  @override
  double computeDistanceToActualBaseline(TextBaseline baseline) {
    return defaultComputeDistanceToFirstActualBaseline(baseline);
  }

  @override
  void paint(PaintingContext context, Offset offset) {
    assert(childCount == 2);

    if (childCount != 2) {
      return;
    }

    defaultPaint(context, offset);
  }

  @override
  void setupParentData(RenderObject child) {
    if (child.parentData is! RichScoreParentData) {
      child.parentData = RichScoreParentData();
    }
  }
}
</code></pre><h2 id="richscoreparentdatascoretextwidth">RichScoreParentData#scoreTextWidth</h2>
<p>上面我们提到<code>RichScoreParentData</code>有唯一一个属性：<code>scoreTextWidth</code>。
那么它的作用是啥呢？
根据<code>RenderRichScore</code>的排版算法，先计算 text 的宽度，★★★★★ 的宽度等于 constraints.biggest.width - textWidth。
这个算法有点小问题：
<a href="https://zxfcumtcs.github.io/img/bad_score.gif">
        <a data-fancybox="gallery" href="https://zxfcumtcs.github.io/img/bad_score.gif">
            <img class="mx-auto" alt="img" src="https://zxfcumtcs.github.io/img/bad_score.gif" />
        </a>
    </a>
由于 textWidth 会因分数的不同，而有细微的差异，最终导致 ★★★★★ 有点闪烁。
为了解决这个问题，我们将 textWidth 的宽度固定为首次计算的 text 宽度+10，并将其存储在<code>RichScoreParentData</code>中(上述代码第<code>42~47</code>行)。</p>
<blockquote>
<p>这种解决方法不一定是最好的，这里主要是演示一下 ParentData 的作用。</p>
</blockquote>
<p>至此，自定义 MultiChild RenderObject 基本完成了。</p>
<h1 id="小结">小结</h1>
<hr>
<p>本文通过实现评分组件，逐步实践了如何自定义 Leaf Render Widget 以及 MultiChild Render Widget。
在这过程中，自定义了 Widget 以及 Render Object，但并没有涉及 Element。
原因是 Element 作为 Widget 与 Render Object 间的桥梁，逻辑相对内聚、独立。
当自定义 Widget 继承自<code>LeafRenderObjectWidget</code>、<code>SingleChildRenderObjectWidget</code>或<code>MultiChildRenderObjectWidget</code>时，一般不用自定义 Element。</p>
<p>自定义 Leaf Render Widget，一般需要以下步骤：</p>
<ul>
<li>
<p>自定义 Widget 继承自<code>LeafRenderObjectWidget</code>，并重写<code>createRenderObject</code>、<code>updateRenderObject</code>方法；</p>
</li>
<li>
<p>自定义 Render Object 继承自</p>
<pre><code>RenderBox
</code></pre><p>：</p>
<ul>
<li>确定<code>sizedByParent</code>为<code>true</code> or <code>false</code>；</li>
<li>为<code>false</code>，重写<code>performLayout</code>方法，执行 layout 并计算 size；</li>
<li>为<code>true</code>，重写<code>performResize</code>方法计算 size、重写<code>performLayout</code>方法执行 layout (若需要)；</li>
<li>如果重写了<code>performLayout</code>方法，则需进一步重写<code>computeMax/MinIntrinsicWidth/Height</code>系列方法；</li>
<li>如需处理用户事件，重写<code>hitTestSelf</code>方法；</li>
<li>重写<code>paint</code>方法，完成最终的绘制。</li>
</ul>
</li>
</ul>
<p>自定义 MultiChild Render Widget，一般需要以下步骤：</p>
<ul>
<li>
<p>自定义 Widget 继承自<code>MultiChildRenderObjectWidget</code>，并重写<code>createRenderObject</code>、<code>updateRenderObject</code>方法；</p>
</li>
<li>
<p>自定义 Render Object 继承自</p>
<pre><code>RenderBox
</code></pre><p>，并 minix</p>
<pre><code>ContainerRenderObjectMixin
</code></pre><p>、</p>
<pre><code>RenderBoxContainerDefaultsMixin
</code></pre><p>：</p>
<ul>
<li>确定<code>sizedByParent</code>为<code>true</code> or <code>false</code>；</li>
<li>为<code>false</code>，重写<code>performLayout</code>方法，对子节点逐个执行 layout 操作并计算 size；</li>
<li>为<code>true</code>，重写<code>performResize</code>方法计算 size、重写<code>performLayout</code>方法执行 layout；</li>
<li>如果重写了<code>performLayout</code>方法，则需进一步重写<code>computeMax/MinIntrinsicWidth/Height</code>系列方法；</li>
<li>重写<code>computeDistanceToActualBaseline</code>方法计算 baseline;</li>
<li>如需处理用户事件，重写<code>hitTestSelf</code>或/和<code>hitTestChildren</code>方法；</li>
<li>自定义 ContainerBoxParentData 子类，用于存储 layout 过程中需要的辅助信息；</li>
<li>重写<code>setupParentData</code>方法，为子节点设置 ParentData；</li>
<li>重写<code>paint</code>方法，对子节点逐个执行 paint 操作。</li>
</ul>
</li>
</ul>
<p>『 深入浅出 Flutter Framework 』系列文章至此全部完成！
这一系列文章围绕 Widget、Element 以及 RenderObject 展开讨论，对 Flutter Framework 有了一个简单的认识。
在此过程中对相关的 BuildOwner、PaintingContext、Layer 以及 PipelineOwner 等也进行了一定的讨论。</p>

        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://luckly.work/">luckly</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://luckly.work/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8B%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B2%E6%9F%93Widget/">https://luckly.work/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8B%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B8%B2%E6%9F%93Widget/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8BRenderObject/">深入浅出之RenderObject</a></li>
        
        <li><a href="/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8BPipelineOwner/">深入浅出之PipelineOwner</a></li>
        
        <li><a href="/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8BlAYER/">深入浅出之Layer</a></li>
        
        <li><a href="/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8BPaintingContext/">深入浅出之PaintingContext</a></li>
        
        <li><a href="/post/flutter_Framework/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E4%B9%8BElement/">深入浅出之Element</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='/tags/Flutter'>Flutter</a></li>
                
            </ul>
            
        </div>
    </article>
    
    

    
    
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "https://github.com/ITmxs/repo"
            issue-term="pathname"
            theme="github-light"
            crossorigin="anonymous"
            async>
      </script>
    </div>
    
</div>

                    <footer id="footer">
    <div>
        &copy; 2021 <a href="https://luckly.work/">早起的年轻人 By luckly</a>
        
        | <a rel="nofollow" target="_blank" href="http://beian.miit.gov.cn/">粤ICP备2021号-1</a>
        
    </div>
    <br />
    <div>
        <div class="github-badge">
            <a href="https://juejin.cn/user/3843548384077192" target="_black" rel="nofollow"><span class="badge-subject">Powered by</span><span class="badge-value bg-blue">掘金</span></a>
        </div>
        <div class="github-badge">
            <a href="https://space.bilibili.com/480883651" target="_black"><span class="badge-subject">Design by</span><span class="badge-value bg-brightgreen">早起的年轻人</span></a>
        </div>
        <div class="github-badge">
            <a href="https://cloud.tencent.com/developer/user/6702670" target="_black"><span class="badge-subject">Theme</span><span class="badge-value bg-yellowgreen">云社区</span></a>
        </div>
    </div>
</footer>


    
    <script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script><script src="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/js/totop.js?v=0.0.0' async=""></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/js/douban.js'></script>
    <script src="/js/copy-to-clipboard.js"></script>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://luckly.work/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://luckly.work/">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9/" title="Nginx文件内容">Nginx文件内容</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%9E%81%E7%AE%80%E6%95%99%E7%A8%8B/" title="Nginx极简教程">Nginx极简教程</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/%E5%8D%81%E5%88%86%E9%92%9F%E5%85%A5%E9%97%A8nginx/" title="十分钟入门Nginx">十分钟入门Nginx</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/go/Goland%E8%BF%9C%E7%A8%8B%E5%BC%80%E5%8F%91%E9%85%8D%E7%BD%AE/" title="Goland远程开发配置">Goland远程开发配置</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E8%AF%BB%E4%B9%A6/%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90/" title="域名解析">域名解析</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/git/%E6%8F%90%E4%BA%A4%E8%BF%87%E7%A8%8B%E7%9C%81%E7%95%A5%E6%9F%90%E4%BA%9B%E6%96%87%E4%BB%B6/" title="提交过程省略某些文件">提交过程省略某些文件</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_DropdownButton%E7%A4%BA%E4%BE%8B/" title="Flutter_DropdownButton示例">Flutter_DropdownButton示例</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_ExpansionPanelList%E5%92%8CExpansionPanelList.radio%E7%A4%BA%E4%BE%8B/" title="Flutter_ExpansionPanelList和ExpansionPanelList">Flutter_ExpansionPanelList和ExpansionPanelList</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter%E5%BE%AE%E4%BF%A1%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E8%B7%B3%E5%9B%9EApp%E6%8C%87%E5%AE%9A%E9%A1%B5%E9%9D%A2/" title="Flutter微信分享链接跳回App指定页面">Flutter微信分享链接跳回App指定页面</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F/%E5%A4%96%E5%8C%85%E5%8F%AF%E8%83%BD%E7%9A%84%E9%97%AE%E9%A2%98/" title="外包可能的问题">外包可能的问题</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title"><a href='/categories/'>分类</a></h3>
<ul class="widget-list">
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (326)</a></li>
    
    <li><a href="https://luckly.work/categories/IT/">IT (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Kotlin/">Kotlin (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Mysql/">Mysql (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (1)</a></li>
    
    <li><a href="https://luckly.work/categories/Vue/">Vue (6)</a></li>
    
    <li><a href="https://luckly.work/categories/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/android/">android (6)</a></li>
    
    <li><a href="https://luckly.work/categories/dart/">dart (96)</a></li>
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (28)</a></li>
    
    <li><a href="https://luckly.work/categories/gin/">gin (25)</a></li>
    
    <li><a href="https://luckly.work/categories/git/">git (4)</a></li>
    
    <li><a href="https://luckly.work/categories/Go/">Go (102)</a></li>
    
    <li><a href="https://luckly.work/categories/gorm/">gorm (4)</a></li>
    
    <li><a href="https://luckly.work/categories/grpc/">grpc (1)</a></li>
    
    <li><a href="https://luckly.work/categories/html/">html (3)</a></li>
    
    <li><a href="https://luckly.work/categories/ios/">ios (1)</a></li>
    
    <li><a href="https://luckly.work/categories/linux/">linux (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (6)</a></li>
    
    <li><a href="https://luckly.work/categories/python/">python (35)</a></li>
    
    <li><a href="https://luckly.work/categories/read/">读书笔记 (6)</a></li>
    
    <li><a href="https://luckly.work/categories/redis/">redis (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E5%8D%95/">书单 (8)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E8%AF%84/">书评 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师 (19)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师 (25)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E5%88%99/">原则 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%9F%BA%E7%A1%80/">基础 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%BF%83%E8%AF%AD/">心语 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%8F%92%E4%BB%B6/">插件 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%95%99%E5%AD%A6/">教学 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%B2%BE%E8%BF%9B/">精进 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%BC%96%E7%A8%8B/">编程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%99%9A%E5%B9%BB/">虚幻 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%91%E6%AD%A5/">跑步 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%BA%BF/">路线 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%A1%B9%E7%9B%AE/">项目 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%AD%85%E5%8A%9B/">魅力 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title"><a href='/tags/'>标签</a></h3>
<div class="tagcloud">
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/IT/">IT</a>
    
    <a href="https://luckly.work/tags/Kotlin/">Kotlin</a>
    
    <a href="https://luckly.work/tags/Mysql/">Mysql</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/Vue/">Vue</a>
    
    <a href="https://luckly.work/tags/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载</a>
    
    <a href="https://luckly.work/tags/android/">android</a>
    
    <a href="https://luckly.work/tags/dart/">dart</a>
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/gin/">gin</a>
    
    <a href="https://luckly.work/tags/git/">git</a>
    
    <a href="https://luckly.work/tags/go/">go</a>
    
    <a href="https://luckly.work/tags/gorm/">gorm</a>
    
    <a href="https://luckly.work/tags/grpc/">grpc</a>
    
    <a href="https://luckly.work/tags/html/">html</a>
    
    <a href="https://luckly.work/tags/ios/">ios</a>
    
    <a href="https://luckly.work/tags/linux/">linux</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/python/">python</a>
    
    <a href="https://luckly.work/tags/redis/">redis</a>
    
    <a href="https://luckly.work/tags/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E5%8D%95/">书单</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E8%AF%84/">书评</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师</a>
    
    <a href="https://luckly.work/tags/%E5%85%A5%E9%97%A8/">入门</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E5%88%99/">原则</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯</a>
    
    <a href="https://luckly.work/tags/%E5%9F%BA%E7%A1%80/">基础</a>
    
    <a href="https://luckly.work/tags/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应</a>
    
    <a href="https://luckly.work/tags/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程</a>
    
    <a href="https://luckly.work/tags/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路</a>
    
    <a href="https://luckly.work/tags/%E5%BF%83%E8%AF%AD/">心语</a>
    
    <a href="https://luckly.work/tags/%E6%8F%92%E4%BB%B6/">插件</a>
    
    <a href="https://luckly.work/tags/%E6%95%99%E5%AD%A6/">教学</a>
    
    <a href="https://luckly.work/tags/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明</a>
    
    <a href="https://luckly.work/tags/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书</a>
    
    <a href="https://luckly.work/tags/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单</a>
    
    <a href="https://luckly.work/tags/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫</a>
    
    <a href="https://luckly.work/tags/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸</a>
    
    <a href="https://luckly.work/tags/%E7%B2%BE%E8%BF%9B/">精进</a>
    
    <a href="https://luckly.work/tags/%E7%BC%96%E7%A8%8B/">编程</a>
    
    <a href="https://luckly.work/tags/%E8%99%9A%E5%B9%BB/">虚幻</a>
    
    <a href="https://luckly.work/tags/%E8%AF%97/">诗</a>
    
    <a href="https://luckly.work/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书笔记</a>
    
    <a href="https://luckly.work/tags/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路</a>
    
    <a href="https://luckly.work/tags/%E8%B7%91%E6%AD%A5/">跑步</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%BA%BF/">路线</a>
    
    <a href="https://luckly.work/tags/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施</a>
    
    <a href="https://luckly.work/tags/%E9%80%9A%E8%AE%AF%E5%BD%95/">通讯录</a>
    
    <a href="https://luckly.work/tags/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学</a>
    
    <a href="https://luckly.work/tags/%E9%A1%B9%E7%9B%AE/">项目</a>
    
    <a href="https://luckly.work/tags/%E9%AD%85%E5%8A%9B/">魅力</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="http://www.topgoer.com/" title="枯藤">枯藤</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gorm.cn/zh_CN/docs/index.html" title="gorm">gorm</a>
        </li>
        
        <li>
            <a target="_blank" href="https://docs.python.org/zh-cn/3/tutorial/index.html" title="python">python</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.liwenzhou.com/" title="李文周">李文周的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://www.xbzweb.com/" title="小包子的博客">小包子的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.flysnow.org/" title="飞雪无情的博客">飞雪无情的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://sliverhorn.com/" title="sliverhorn的博客">sliverhorn的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://yuedu.baidu.com/ebook/14a722970740be1e640e9a3e" title="Android Gradle权威指南">Android Gradle权威指南</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gesdh.cn/" title="小格子">格子导航</a>
        </li>
        
        <li>
            <a target="_blank" href="https://itachi.xyz/" title="阿林">itachi&#39;s Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://darjun.github.io/" title="大俊">大俊Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://geektutu.com/post/quick-golang.html" title="极客兔兔">极客兔兔Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="http://zxfcumtcs.github.io/" title="赵雪峰">雪峰Blog</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://luckly.work/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
</body>

</html>